bitkeeper revision 1.1159.1.70 (41208580UQYjPMyX6IwpTt7euiLMgg)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 16 Aug 2004 09:59:28 +0000 (09:59 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 16 Aug 2004 09:59:28 +0000 (09:59 +0000)
Document cpu_weight config field and check value type.

docs/xen_config.html
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py
tools/python/xen/xm/opts.py

index 81258c51893790a85b65edc4ecc1a4c099d93e43..00628c9bfea79ee7ded37336abe6d9d66940b294 100644 (file)
@@ -61,6 +61,7 @@ The top-level element, a virtual machine configuration.
     <li>id: int, optional, default generated. Domain unique id.
     <li>memory: int, required. Domain memory in MB.
     <li>cpu: int, optional. Cpu to run on.
+    <li>cpu_weight, float, optional, default 1. Cpu weight - controls share of CPU.
     <li>image: linux | netbsd | ..., required. Domain image (OS-specific element).
     <li>backend: any backend device type, optional, default none.
     <li>device: any device type, optional, repeats. Device.
index 8b47598c935694b1ec6695c52395dc9c6f71e479..602575d0ba293f9a1540a169ca6fc851a0a0d8aa 100644 (file)
@@ -369,6 +369,7 @@ class XendDomainInfo:
         self.config = None
         self.id = None
         self.dom = None
+        self.cpu_weight = 1
         self.start_time = None
         self.name = None
         self.memory = None
@@ -499,7 +500,10 @@ class XendDomainInfo:
         try:
             self.name = sxp.child_value(config, 'name')
             self.check_name(self.name)
-           self.cpu_weight = float(sxp.child_value(config, 'cpu_weight', '1'))
+            try:
+                self.cpu_weight = float(sxp.child_value(config, 'cpu_weight', '1'))
+            except:
+                raise VmError('invalid cpu weight')
             if self.restore and self.dom:
                 xc.domain_setname(self.dom, self.name)
             self.memory = int(sxp.child_value(config, 'memory'))
index 6d70bdcba6f1c516e03aa2e28cb22d08aab8df5c..1a05da4e145057ea9cb3a7a44d958b448fad7649 100644 (file)
@@ -101,9 +101,10 @@ gopts.var('memory', val='MEMORY',
           fn=set_value, default=128,
           use="Domain memory in MB.")
 
-gopts.var('cpu_weight', val='CPU_WEIGHT',
-          fn=set_value, default=1,
-          use="CPU weight.")
+gopts.var('cpu_weight', val='WEIGHT',
+          fn=set_float, default=1,
+          use="""Set the new domain's cpu weight. WEIGHT is a float that controls the
+domain's share of the cpu.""")
 
 gopts.var('console', val='PORT',
           fn=set_int, default=None,
index 9f34b6773ca93a17537777078eb0ddedb41503b0..a46ab3c1f023bfd7a30211397555cc9e55968730 100644 (file)
@@ -409,7 +409,7 @@ def set_bool(opt, k, v):
         
 
 def set_value(opt, k, v):
-    """Set an option to a valoue."""
+    """Set an option to a value."""
     opt.set(v)
 
 def set_int(opt, k, v):
@@ -420,6 +420,14 @@ def set_int(opt, k, v):
         opt.opts.err('Invalid value: ' + str(v))
     opt.set(v)
 
+def set_float(opt, k, v):
+    """Set an option to a float value."""
+    try:
+        v = float(v)
+    except:
+        opt.opts.err('Invalid value: ' + str(v))
+    opt.set(v)
+
 def append_value(opt, k, v):
     """Append a value to a list option."""
     opt.append(v)